/** 
 * This file is a part of qloudgen-sec. 
 * You can redistribute qloudgen-sec and/or modify it under the terms of the Lesser GNU General Public License version 3. 
 * qloudgen-sec is distributed WITHOUT ANY WARRANTY. 
 *
 * See the Lesser GNU General Public License for more details at http://www.gnu.org/licenses/. 
 **/
package org.qloudgen.sec.util;

/**
 * <p>Title: String tools.</p>
 * <p>Description: Implementation common string method.</p>
 * <p>Copyright: qloudgen/sec 2011</p>
 * @author <a href="mailto:hyq.dd.sun@gmail.com">glue.3M</a>
 */
public final class StringUtil {
	/**
	 * Returns the first sub string after target and exclude target.
	 *
	 * @param str
	 * @param target
	 * @return String
	 */
	public static String afterString(String str , String target) {
		//
		if ( str == null || target == null ) {
			return str;
		}
		//
		int begin = str.indexOf( target );
		if ( begin < 0 ) {
			return str;
		}
		//
		return str.substring( begin + target.length() );
	}

	/**
	 * Returns the first sub string before target and exclude target.
	 *
	 * @param str
	 * @param target
	 * @return String
	 */
	public static String beforeString(String str , String target) {
		//
		if ( str == null || target == null ) {
			return str;
		}
		//
		int begin = str.indexOf( target );
		if ( begin < 0 ) {
			return str;
		}
		//
		return str.substring( 0 , begin );
	}
	
	/**
	 * Returns object real class and hash code.
	 *
	 * @param obj
	 * @return String
	 */
	public static String toString(Object obj) {
		//
		return obj.getClass().getName() + "@" + Integer.toHexString( obj.hashCode() );
	}
	
	/**
	 * Returns if a string is real blank.
	 *
	 * @param target
	 * @return boolean
	 */
	public static boolean isBlank(String target) {
		return ( target == null || "".equals( target.trim() ) );
	}
	
	/**
	 * Returns string compare result.
	 *
	 * @param str1
	 * @param str2
	 * @return boolean
	 */
	public static boolean compare(String str1 , String str2) {
		//
		return ( str1 != null ? str1.equals( str2 ) : ( str2 == null ) );
	}
}